﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YJKFamilyLibDataManager;

namespace DoorAndWindow
{
	internal partial class DlgDoorWinInsert : System.Windows.Forms.Form
	{
		public bool AddTag
		{
			get
			{
				return this.chbAddTag.Checked;
			}
		}

		public DbFamily TagDbFamily
		{
			get
			{
				return (DbFamily)this.cbxSymbol.SelectedItem;
			}
		}

		public string FirstTagString
		{
			get
			{
				return this.tbxStart.Text.Trim();
			}
		}

		public string SecondTagString
		{
			get
			{
				return this.tbxTag.Text.Trim();
			}
		}

		public DlgDoorWinInsert(UIApplication uiApp, bool boDoor)
		{
			try
			{
				this.m_application = uiApp;
				this.m_document = uiApp.ActiveUIDocument.Document;
				this.m_datum = new DoorWinDatum();
				this.archDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Architecture, this.m_application.Application.VersionNumber);
				this.sysDB = FamilyLibDatabase.GetSqliteDB(SubjectType.System, this.m_application.Application.VersionNumber);
				this.tempInfo = Assist.FileUtil.GetTempDataFile();
				this.fileInfo = Assist.FileUtil.GetProjConfigFile(this.m_document);
				this.InitializeComponent();
				this.cbxPrompt.Clear();
				this.cbxPrompt.AddItem("1");
				this.cbxPrompt.AddItem("2");
				this.cbxPrompt.AddItem("3");
				this.cbxPrompt.AddItem("4");
				this.cbxPrompt.AddItem("5");
				this.cbxPrompt.AddItem("6");
				this.cbxPrompt.AddItem("7");
				this.cbxPrompt.AddItem("8");
				this.cbxPrompt.AddItem("9");
				this.cbxPrompt.AddItem("10");
				this.cbxDis.Clear();
				this.cbxDis.AddItem("0");
				this.cbxDis.AddItem("60");
				this.cbxDis.AddItem("100");
				this.cbxDis.AddItem("120");
				this.cbxDis.AddItem("180");
				this.cbxDis.AddItem("200");
				this.cbxDis.AddItem("240");
				this.cbxDis.AddItem("300");
				this.cbxDis.AddItem("360");
				this.cbxDis.AddItem("400");
				this.cbxDis.AddItem("500");
				this.cbxDis.AddItem("600");
				this.cbxDis.AddItem("700");
				this.cbxDis.AddItem("800");
				this.cbxDis.AddItem("900");
				this.cbxDis.AddItem("1000");
				this.isDoor = boDoor;
				if (boDoor)
				{
					this.radioBtnDoor.Checked = true;
					this.radioBtnWin.Checked = false;
					this.Text = "插入门";
					this.labType.Text = "门槛";
					this.initDoorCbxFamily();
					this.initCbxDoorHeight();
					this.initDoorInsertType();
					this.initDoorCbxDis();
					this.initDoorCbxPrompt();
					this.cbxHeight.AddItem("0");
					this.cbxHeight.AddItem("50");
					this.cbxHeight.AddItem("60");
					this.cbxHeight.AddItem("100");
					this.cbxHeight.AddItem("150");
					this.cbxHeight.AddItem("200");
					this.cbxHeight.AddItem("300");
					this.cbxHeight.AddItem("600");
				}
				else
				{
					this.radioBtnDoor.Checked = false;
					this.radioBtnWin.Checked = true;
					this.Text = "插入窗";
					this.labType.Text = "窗台";
					this.initWinCbxFamily();
					this.initCbxWinHeight();
					this.initWinInsertType();
					this.initWinCbxDis();
					this.initWinCbxPrompt();
					this.cbxHeight.AddItem("0");
					this.cbxHeight.AddItem("300");
					this.cbxHeight.AddItem("400");
					this.cbxHeight.AddItem("500");
					this.cbxHeight.AddItem("600");
					this.cbxHeight.AddItem("700");
					this.cbxHeight.AddItem("800");
					this.cbxHeight.AddItem("900");
					this.cbxHeight.AddItem("1000");
					this.cbxHeight.AddItem("1200");
				}
				this.chbAddTag.Checked = false;
				this.InitType(boDoor);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		private void initDoorCbxFamily()
		{
			this.cbxType.Items.Clear();
			this.cbxFamily.Items.Clear();
			try
			{
				DbCategory dbCategory = this.archDB.CategoryTable["门"];
				List<DbFamily> allFamilies = dbCategory.GetAllFamilies(true, CheckType.All);
				foreach (DbFamily item in allFamilies)
				{
					this.cbxFamily.Items.Add(item);
				}
				if (this.cbxFamily.Items.Count > 0)
				{
					this.cbxFamily.SelectedIndex = 0;
					string text = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "族名").Trim();
                    string text2 = Assist.FileUtil.GetDataFromConfigFile(this.fileInfo.FullName, "全局配置", "门样式").Trim();
					string b;
					if (text != "")
					{
						b = text;
					}
					else
					{
						b = text2;
					}
					foreach (object obj in this.cbxFamily.Items)
					{
						string a = ((DbFamily)obj).Name.Trim();
						if (a == b)
						{
							this.cbxFamily.SelectedItem = obj;
							break;
						}
					}
				}
			}
			catch
			{
			}
		}

		private void initWinCbxFamily()
		{
			this.cbxType.Items.Clear();
			this.cbxFamily.Items.Clear();
			try
			{
				DbCategory dbCategory = this.archDB.CategoryTable["窗"];
				List<DbFamily> allFamilies = dbCategory.GetAllFamilies(true, CheckType.All);
				foreach (DbFamily item in allFamilies)
				{
					this.cbxFamily.Items.Add(item);
				}
				if (this.cbxFamily.Items.Count > 0)
				{
					this.cbxFamily.SelectedIndex = 0;
					string text = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "族名").Trim();
                    string text2 = Assist.FileUtil.GetDataFromConfigFile(this.fileInfo.FullName, "全局配置", "窗样式").Trim();
					string b;
					if (text != "")
					{
						b = text;
					}
					else
					{
						b = text2;
					}
					foreach (object obj in this.cbxFamily.Items)
					{
						string a = ((DbFamily)obj).Name.Trim();
						if (a == b)
						{
							this.cbxFamily.SelectedItem = obj;
							break;
						}
					}
				}
			}
			catch
			{
			}
		}

		private void initCbxDoorHeight()
		{
			try
			{
				int num = Convert.ToInt32(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "高度"));
				this.cbxHeight.Text = num.ToString();
			}
			catch
			{
				this.cbxHeight.Text = "0";
			}
		}

		private void initCbxWinHeight()
		{
			try
			{
				int num = Convert.ToInt32(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "高度"));
				this.cbxHeight.Text = num.ToString();
			}
			catch
			{
				this.cbxHeight.Text = "600";
			}
		}

		private void initDoorCbxDis()
		{
			try
			{
				double num = Convert.ToDouble(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "距离"));
				this.cbxDis.Text = num.ToString();
			}
			catch
			{
				this.cbxDis.Text = "200";
			}
		}

		private void initWinCbxDis()
		{
			try
			{
				double num = Convert.ToDouble(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "距离"));
				this.cbxDis.Text = num.ToString();
			}
			catch
			{
				this.cbxDis.Text = "200";
			}
		}

		private void initWinInsertType()
		{
			try
			{
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "插入类型");
				string a;
				if ((a = dataFromTempFile) != null)
				{
					if (a == "eByPickPoint")
					{
						this.radioBtnPick.Checked = true;
						this.m_nInsertType = InsertType.eByPickPoint;
						goto IL_10E;
					}
					if (a == "eByButtress")
					{
						this.radioBtnButtf.Checked = true;
						this.cbxDis.Visible = true;
						this.labelDis.Visible = true;
						this.m_nInsertType = InsertType.eByButtress;
						goto IL_10E;
					}
					if (a == "eByEqual")
					{
						this.radioBtnEqul.Checked = true;
						this.cbxPrompt.Visible = true;
						this.labelPrompt.Visible = true;
						this.m_nInsertType = InsertType.eByEqual;
						goto IL_10E;
					}
					if (a == "eByGridLineEqual")
					{
						this.cbxPrompt.Visible = true;
						this.labelPrompt.Visible = true;
						this.radioBtnEqualByGrid.Checked = true;
						this.m_nInsertType = InsertType.eByGridLineEqual;
						goto IL_10E;
					}
				}
				this.radioBtnPick.Checked = true;
				this.m_nInsertType = InsertType.eByPickPoint;
				IL_10E:;
			}
			catch
			{
				this.radioBtnPick.Checked = true;
			}
		}

		private void initDoorInsertType()
		{
			try
			{
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "插入类型");
				string a;
				if ((a = dataFromTempFile) != null)
				{
					if (a == "eByPickPoint")
					{
						this.radioBtnPick.Checked = true;
						this.m_nInsertType = InsertType.eByPickPoint;
						goto IL_10E;
					}
					if (a == "eByButtress")
					{
						this.radioBtnButtf.Checked = true;
						this.cbxDis.Visible = true;
						this.labelDis.Visible = true;
						this.m_nInsertType = InsertType.eByButtress;
						goto IL_10E;
					}
					if (a == "eByEqual")
					{
						this.radioBtnEqul.Checked = true;
						this.cbxPrompt.Visible = true;
						this.labelPrompt.Visible = true;
						this.m_nInsertType = InsertType.eByEqual;
						goto IL_10E;
					}
					if (a == "eByGridLineEqual")
					{
						this.cbxPrompt.Visible = true;
						this.labelPrompt.Visible = true;
						this.radioBtnEqualByGrid.Checked = true;
						this.m_nInsertType = InsertType.eByGridLineEqual;
						goto IL_10E;
					}
				}
				this.radioBtnPick.Checked = true;
				this.m_nInsertType = InsertType.eByPickPoint;
				IL_10E:;
			}
			catch
			{
				this.radioBtnPick.Checked = true;
			}
		}

		private void initDoorCbxPrompt()
		{
			try
			{
				int num = Convert.ToInt32(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "数量"));
				this.cbxPrompt.Text = num.ToString();
			}
			catch
			{
				this.cbxPrompt.Text = "2";
			}
		}

		private void initWinCbxPrompt()
		{
			try
			{
				int num = Convert.ToInt32(Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "数量"));
				this.cbxPrompt.Text = num.ToString();
			}
			catch
			{
				this.cbxPrompt.Text = "2";
			}
		}

		private void InitType(bool isDoor)
		{
			if (!isDoor)
			{
				this.cbxSymbol.Items.Clear();
				List<DbCategory> all = this.sysDB.CategoryTable.GetAll();
				foreach (DbCategory dbCategory in all)
				{
					if (dbCategory.Name == "窗标记")
					{
						List<DbFamily> allFamilies = dbCategory.GetAllFamilies(true, CheckType.All);
						foreach (DbFamily item in allFamilies)
						{
							this.cbxSymbol.Items.Add(item);
						}
					}
				}
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "标记样式");
				foreach (object obj in this.cbxSymbol.Items)
				{
					string a = obj.ToString();
					if (a == dataFromTempFile)
					{
						this.cbxSymbol.SelectedItem = obj;
						break;
					}
					if (this.cbxSymbol.Items.Count > 0)
					{
						this.cbxSymbol.SelectedIndex = 0;
					}
				}
				this.tbxStart.Text = "C";
				return;
			}
			List<DbCategory> all2 = this.sysDB.CategoryTable.GetAll();
			foreach (DbCategory dbCategory2 in all2)
			{
				if (dbCategory2.Name == "门标记")
				{
					List<DbFamily> allFamilies2 = dbCategory2.GetAllFamilies(true, CheckType.All);
					foreach (DbFamily item2 in allFamilies2)
					{
						this.cbxSymbol.Items.Add(item2);
					}
				}
			}
			string dataFromTempFile2 = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "标记样式");
			foreach (object obj2 in this.cbxSymbol.Items)
			{
				string a2 = obj2.ToString();
				if (a2 == dataFromTempFile2)
				{
					this.cbxSymbol.SelectedItem = obj2;
					break;
				}
				if (this.cbxSymbol.Items.Count > 0)
				{
					this.cbxSymbol.SelectedIndex = 0;
				}
			}
			this.tbxStart.Text = "M";
		}

		private void radioBtnPick_CheckedChanged(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByPickPoint;
			this.labelDis.Visible = false;
			this.cbxDis.Visible = false;
		}

		private void radioBtnPick_MouseEnter(object sender, EventArgs e)
		{
			this.toolTip.Show("", (RadioButton)sender);
		}

		public XYZ PickPoint(UIDocument uidoc)
		{
            ObjectSnapTypes objectSnapTypes = (ObjectSnapTypes)17;
			return uidoc.Selection.PickPoint(objectSnapTypes, "选择插入点");
		}

		private void SelectWall()
		{
			UIDocument uidocument = new UIDocument(this.m_document);
			Selection selection = uidocument.Selection;
			Reference reference = selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
			this.m_document.GetElement(reference).GetType().ToString();
		}

		private void radioBtnPick_MouseLeave(object sender, EventArgs e)
		{
			this.toolTip.Hide((RadioButton)sender);
		}

		private void radioBtnEqual_MouseEnter(object sender, EventArgs e)
		{
			this.toolTip.Show("均分墙段插入", (RadioButton)sender);
		}

		private void radioBtnEqual_MouseLeave(object sender, EventArgs e)
		{
			this.toolTip.Hide((RadioButton)sender);
		}

		private void radioBtnButtf_MouseEnter(object sender, EventArgs e)
		{
			this.toolTip.Show("垛宽插入", (RadioButton)sender);
		}

		private void radioBtnButtf_MouseLeave(object sender, EventArgs e)
		{
			this.toolTip.Hide((RadioButton)sender);
		}

		private void radioBtnOrder_MouseEnter(object sender, EventArgs e)
		{
			this.toolTip.Show("连续等距插入", (RadioButton)sender);
		}

		private void radioBtnOrder_MouseLeave(object sender, EventArgs e)
		{
			this.toolTip.Hide((RadioButton)sender);
		}

		private void radioBtnFull_CheckedChanged(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByFullWall;
			this.cbxDis.Visible = false;
			this.labelDis.Visible = false;
		}

		private void radioBtnFull_MouseEnter(object sender, EventArgs e)
		{
			this.toolTip.Show("整段墙插入", (RadioButton)sender);
		}

		private void radioBtnFull_MouseLeave(object sender, EventArgs e)
		{
			this.toolTip.Hide((RadioButton)sender);
		}

		private Bitmap GetPreview(System.Drawing.Size size, string familyName, string familySymbolName, BuiltInCategory bc)
		{
			Bitmap result = new Bitmap(size.Width, size.Height);
			FamilySymbol familySymbol = ElementFiltering.FindElementType(this.m_document, typeof(FamilySymbol), familyName, familySymbolName, bc) as FamilySymbol;
			try
			{
				result = familySymbol.GetPreviewImage(size);
			}
			catch
			{
			}
			return result;
		}

		private BitmapSource ToConvertToImageSource(Bitmap g)
		{
			if (g == null)
			{
                System.Windows.Forms.MessageBox.Show("null", "盈建科提示");
				return null;
			}
			return Imaging.CreateBitmapSourceFromHBitmap(g.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.m_datum.m_nInsertType = this.m_nInsertType;
			DbFamily dbFamily = (DbFamily)this.cbxFamily.SelectedItem;
			string name = this.cbxType.SelectedItem.ToString();
			this.m_datum.m_symbol = dbFamily.Database.TypeTable[dbFamily, name];
			if (this.m_nInsertType == InsertType.eByEqual)
			{
				this.m_datum.m_nEqualNum = Convert.ToInt32(this.cbxPrompt.Text);
			}
			else if (this.m_nInsertType == InsertType.eByButtress)
			{
				this.m_datum.m_dButtressWidth = Convert.ToDouble(this.cbxDis.Text);
			}
			else if (this.m_nInsertType == InsertType.eByOrder)
			{
				this.m_datum.m_dOrderDist = Convert.ToDouble(this.cbxDis.Text);
			}
			else if (this.m_nInsertType == InsertType.eByFullWall)
			{
				this.m_datum.m_dOrderDist = Convert.ToDouble(this.cbxDis.Text);
			}
			else if (this.m_nInsertType == InsertType.eByGridLineEqual)
			{
				this.m_datum.m_nEqualNum = Convert.ToInt32(this.cbxPrompt.Text);
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary.Add("族名", this.cbxFamily.Text);
			dictionary.Add("类型名", this.cbxType.Text);
			dictionary.Add("插入类型", this.m_nInsertType.ToString());
			dictionary.Add("高度", this.cbxHeight.Text);
			dictionary.Add("数量", this.cbxPrompt.Text);
			dictionary.Add("距离", this.cbxDis.Text);
			dictionary.Add("标记样式", this.cbxSymbol.Text);
			if (this.isDoor)
			{
				Assist.FileUtil.WriteTempData(this.tempInfo.FullName, "门插入", ConfigData.DoorWinData, dictionary);
				return;
			}
			Assist.FileUtil.WriteTempData(this.tempInfo.FullName, "窗插入", ConfigData.DoorWinData, dictionary);
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void btnInputFamily_Click(object sender, EventArgs e)
		{
			Transaction transaction = new Transaction(this.m_document, "InputDoorFamily");
			transaction.Start();
			if (AssistFunc.LoadStandardFamily(this.m_application))
			{
				TaskDialog.Show("导入族", "族导入成功!");
			}
			else
			{
				TaskDialog.Show("导入族", "族导入失败!");
			}
			transaction.Commit();
		}

		private void radioBtnPick_Click(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByPickPoint;
			this.labelPrompt.Visible = false;
			this.cbxPrompt.Visible = false;
			this.labelDis.Visible = false;
			this.cbxDis.Visible = false;
			this.radioBtnPick.Checked = true;
			this.radioBtnEqualByGrid.Checked = false;
			this.radioBtnButtf.Checked = false;
			this.radioBtnEqul.Checked = false;
		}

		private void radioBtnButtf_Click(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByButtress;
			this.cbxDis.Visible = true;
			this.labelDis.Visible = true;
			this.cbxPrompt.Visible = false;
			this.labelPrompt.Visible = false;
			this.radioBtnPick.Checked = false;
			this.radioBtnEqul.Checked = false;
			this.radioBtnButtf.Checked = true;
			this.radioBtnEqualByGrid.Checked = false;
		}

		private void DlgDoorInsert_Load(object sender, EventArgs e)
		{
			this.radioBtnDoor.Checked = true;
		}

		private void toolStripButton3_Click(object sender, EventArgs e)
		{
			this.radioBtnDoor.Checked = true;
			this.radioBtnWin.Checked = false;
			this.Text = "门插入";
			this.labType.Text = "门槛";
			this.cbxHeight.SelectedIndex = 0;
			DlgDoorWinInsert.bc = BuiltInCategory.OST_Doors;
		}

		private void toolStripButton4_Click(object sender, EventArgs e)
		{
			this.radioBtnDoor.Checked = false;
			this.radioBtnWin.Checked = true;
			this.Text = "窗插入";
			this.labType.Text = "窗台";
			this.cbxHeight.SelectedIndex = 4;
			DlgDoorWinInsert.bc = BuiltInCategory.OST_Windows;
		}

		private void cbxFamily_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.ResetTypeCmb();
		}

		private void ResetTypeCmb()
		{
			if (this.cbxFamily.SelectedItem != null)
			{
				this.cbxType.Items.Clear();
				DbFamily dbFamily = (DbFamily)this.cbxFamily.SelectedItem;
				this.pbPreview.Image = AssistFunc.ResizeImage((Bitmap)dbFamily.Image, 150, 150);
				List<string> symbols = dbFamily.Symbols;
				if (symbols.Count > 0)
				{
					for (int i = 0; i < symbols.Count; i++)
					{
						this.cbxType.Items.Add(symbols[i]);
					}
					if (this.cbxType.Items.Count > 0)
					{
						this.cbxType.SelectedIndex = 0;
					}
					if (this.isDoor)
					{
						string b = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "门插入", "类型名").Trim();
						IEnumerator enumerator = this.cbxType.Items.GetEnumerator();
						{
							while (enumerator.MoveNext())
							{
								object obj = enumerator.Current;
								string text = (string)obj;
								if (text.Trim() == b)
								{
									this.cbxType.SelectedItem = text;
									break;
								}
							}
							goto IL_1C1;
						}
					}
					string b2 = Assist.FileUtil.GetDataFromTempFile(this.tempInfo.FullName, "窗插入", "类型名").Trim();
					foreach (object obj2 in this.cbxType.Items)
					{
						string text2 = (string)obj2;
						if (text2.Trim() == b2)
						{
							this.cbxType.SelectedItem = text2;
							break;
						}
					}
					IL_1C1:
					this.btnOK.Enabled = true;
					return;
				}
				this.btnOK.Enabled = false;
			}
		}

		private void radioBtnEqul_Click(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByEqual;
			this.cbxPrompt.Visible = true;
			this.labelPrompt.Visible = true;
			this.cbxDis.Visible = false;
			this.labelDis.Visible = false;
			this.radioBtnPick.Checked = false;
			this.radioBtnEqul.Checked = true;
			this.radioBtnButtf.Checked = false;
			this.radioBtnEqualByGrid.Checked = false;
		}

		private void radioBtnEqualByGrid_Click(object sender, EventArgs e)
		{
			this.m_nInsertType = InsertType.eByGridLineEqual;
			this.cbxPrompt.Visible = true;
			this.labelPrompt.Visible = true;
			this.cbxDis.Visible = false;
			this.labelDis.Visible = false;
			this.radioBtnEqul.Checked = false;
			this.radioBtnPick.Checked = false;
			this.radioBtnEqualByGrid.Checked = true;
			this.radioBtnButtf.Checked = false;
		}

		private void tbxTag_Leave(object sender, EventArgs e)
		{
			if (this.tbxTag.Text == "")
			{
				this.tbxTag.Text = "<默认编号>";
			}
		}

		private void tbxTag_MouseClick(object sender, MouseEventArgs e)
		{
			if (this.tbxTag.Text == "<默认编号>")
			{
				this.tbxTag.Text = "";
			}
		}

		private void btnNewType_Click(object sender, EventArgs e)
		{
			if (this.cbxFamily.SelectedIndex < 0)
			{
				return;
			}
			string currentFamilySymbolName = this.cbxType.SelectedItem.ToString();
			DbFamily dbFamily = (DbFamily)this.cbxFamily.SelectedItem;
			List<string> symbols = dbFamily.Symbols;
			List<ParameterData> list = new List<ParameterData>();
			if (!this.GetParameterData(ref list))
			{
				return;
			}
			if (list.Count == 0)
			{
                System.Windows.Forms.MessageBox.Show("无有效尺寸参数（缺少尺寸参数或者参数分组错误）", "盈建科提示");
				return;
			}
			using (DlgNewSize dlgNewSize = new DlgNewSize(currentFamilySymbolName, symbols, list))
			{
				if (dlgNewSize.ShowDialog() == DialogResult.OK)
				{
					string newTypeName = dlgNewSize.NewTypeName;
					DataTable dataTable = dbFamily.Database.TypeTable.DataTable(dbFamily);
					dataTable.Clear();
					DataRow dataRow = dataTable.NewRow();
					dataRow["规格名"] = newTypeName;
					foreach (ParameterData parameterData in list)
					{
						dataRow[parameterData.ParName] = AssistFunc.feetToMM(parameterData.ParValue);
					}
					dataTable.Rows.Add(dataRow);
					dbFamily.AddType(dataTable);
					this.ResetTypeCmb();
					int i = 0;
					int num = -1;
					while (i < this.cbxType.Items.Count)
					{
						object obj = this.cbxType.Items[i];
						if (obj.ToString().CompareTo(newTypeName) == 0)
						{
							num = i;
							this.cbxType.SelectedIndex = num;
							break;
						}
						i++;
					}
					if (num == -1 && this.cbxType.Items.Count > 0)
					{
						this.cbxType.SelectedIndex = this.cbxType.Items.Count - 1;
					}
				}
			}
		}

		private bool GetParameterData(ref List<ParameterData> parameterDataList)
		{
			DbFamily dbFamily = (DbFamily)this.cbxFamily.SelectedItem;
			if (dbFamily == null)
			{
				return false;
			}
			if (this.archDB == null)
			{
				return false;
			}
			string name = this.cbxType.SelectedItem.ToString();
			DbFamilySymbol dbFamilySymbol = this.archDB.TypeTable[dbFamily, name];
			if (dbFamilySymbol == null)
			{
				return false;
			}
			List<DbParameter> @params = dbFamilySymbol.Params;
			foreach (DbParameter dbParameter in @params)
			{
                if ((int)dbParameter.ParamDefinition.BuiltInParameterGroup == -5000101)
				{
					double parValue = 0.0;
					try
					{
						parValue = AssistFunc.mmToFeet(Convert.ToDouble(dbParameter.Value.ToString()));
					}
					catch (Exception)
					{
						continue;
					}
					ParameterData item = new ParameterData(dbParameter.ParamDefinition.Name, parValue);
					parameterDataList.Add(item);
				}
			}
			return true;
		}

		private void cbxSymbol_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		public InsertType m_nInsertType = InsertType.eByPickPoint;

		public DoorWinDatum m_datum;

		public static BuiltInCategory bc = BuiltInCategory.OST_Doors;

		private FileInfo tempInfo;

		private FileInfo fileInfo;

		private UIApplication m_application;

		private Document m_document;

		private FamilyLibDatabase archDB;

		private FamilyLibDatabase sysDB;

		private bool isDoor;
	}
}
